<template>
	<view class="container">
		<canvas canvas-id="myCanvas" class="canvas" :style="{backgroundColor:'black', width: '100%', height: '80%'}">
			<view class="top-case">
				<view class="top-btn" @click="selectTopRadio" v-for="(radioValue, index) in topRadioValues" :key="index">
					{{ radioValue }}
				</view>
			</view>
			<view class="bottom-case">
				<view class="bottom-btn" @click="selectBottomRadio" v-for="(radioValue, index) in bottomRadioValues" :key="index">
					{{ radioValue }}
				</view>
			</view>
		</canvas>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				topRadioValues: ['选项 1', '选项 2', '选项 3'],
				bottomRadioValues: ['选项 1', '选项 2', '选项 3'],
				topPageX: null,
				topPageY: null,
				bottomPageX: null,
				bottomPageY: null
			};
		},
		methods: {
			handleClick(event) {
				console.log(event)

			},
			selectTopRadio(event) {
				const arrayList = event.touches[0];
				console.log(`X 坐标: ${arrayList.pageX}, Y 坐标: ${arrayList.pageY}`);
				this.topPageX = arrayList.pageX
				this.topPageY = arrayList.pageY
			},
			selectBottomRadio(event) {
				const arrayList = event.touches[0];
				console.log(`X 坐标: ${arrayList.pageX}, Y 坐标: ${arrayList.pageY}`);
				this.bottomPageX = arrayList.pageX
				this.bottomPageY = arrayList.pageY
				this.drawLine();
			},
			drawLine() {
				const ctx = uni.createCanvasContext('myCanvas');
				ctx.beginPath();
				ctx.moveTo(this.topPageX, this.topPageY);
				ctx.lineTo(this.bottomPageX, this.bottomPageY);
				ctx.strokeStyle = 'red';
				ctx.stroke();
				ctx.draw();
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import "~@/static/styles/variables.scss";

	.container {
		text-align: center;
		padding: 30rpx;
		height: 100vh;
	}
	.canvas{
		display: flex;
		align-items: center;
	}
	.top-case {
		margin-bottom: 80rpx;
		display: flex;
	}

	.top-btn {
		width: 80rpx;
		height: 80rpx;
		background-color: red;
		margin-right: 30rpx;
	}
	
	.bottom-case {
		display: flex;
	}

	.bottom-btn {
		width: 80rpx;
		height: 80rpx;
		background-color: blue;
		margin-right: 30rpx;
	}
</style>